package com.hs.service.impl;

import com.hs.dao.TeacherDao;
import com.hs.dao.impl.TeacherDaoImpl;
import com.hs.pojo.Teacher;
import com.hs.service.TeacherService;
import com.hs.util.Page;

import java.util.List;

public class TeacherServiceImpl implements TeacherService {
    TeacherDao teacherDao=new TeacherDaoImpl();
    @Override
    public Page<Teacher> selectTeachers(int pageNum) {
        //定义每页显示的条数
        int pageSize=2;
        //查询所有的数据的总条数
        int count = teacherDao.SelectCount();
        // 创建page对象 自动进行计算处理
        Page<Teacher> page = new Page<>(pageNum, pageSize, count);
        List<Teacher> teachers = teacherDao.selectTeacher(page.getStartIndex(), pageSize);
        //把对象集合封装到page对象中
        page.setList(teachers);
        return page;
    }

    @Override
    public int insertTeacher(Teacher teacher) {

        return teacherDao.insertTeacher(teacher);
    }

    @Override
    public Teacher selectTeacherById(int id) {
        return teacherDao.selectTeacherById(id);
    }

    @Override
    public int updateTeacher(Teacher teacher) {
        return teacherDao.updateTeacher(teacher);
    }

    @Override
    public int deleteTeacher(int id) {
        return teacherDao.deleteTeacher(id);
    }
}
